#
# Copyright (C) 2013 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=poppler_lede
PKG_VERSION:=24.05.0
PKG_RELEASE:=1

PKG_SRC_NAME:=poppler

PKG_SOURCE:=$(PKG_SRC_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=http://poppler.freedesktop.org/
PKG_HASH:=d8c5eb30b50285ad9f0af8c6335cc2d3b9597fca475cbc2598a5479fa379f779

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SRC_NAME)-$(PKG_VERSION)
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_SRC_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/poppler_lede
    SECTION:=utils
    CATEGORY:=Printing
    SUBMENU:=Utilities
    TITLE:=(LEDE) Poppler PDF rendering library
    DEPENDS:=+libpng +libtiff +libjpeg +zlib +lcms2_lede +fontconfig +libpthread +libfreetype \
             +libstdcpp +libcairo_lede +glib2 +libintl-full +curl +libnss +nspr
    URL:=http://poppler.freedesktop.org/
endef

define Package/poppler_lede/description
	Poppler command line tools
endef

TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include/freetype2
TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib -lfreetype

CMAKE_OPTIONS += \
	-DENABLE_GLIB:BOOL=OFF \
	-DENABLE_GTK_DOC:BOOL=OFF \
	-DBUILD_GTK_TESTS:BOOL=OFF \
	-DENABLE_QT5:BOOL=OFF \
	-DENABLE_QT6:BOOL=OFF \
	-DBUILD_CPP_TESTS:BOOL=OFF \
	-DBUILD_GTK_TESTS:BOOL=OFF \
	-DBUILD_QT5_TESTS:BOOL=OFF \
	-DBUILD_QT6_TESTS:BOOL=OFF \
	-DENABLE_CPP:BOOL=ON \
	-DENABLE_ZLIB_UNCOMPRESS:BOOL=ON \
	-DENABLE_LIBOPENJPEG:STRING=none \
	-DENABLE_DCTDECODER:STRING=libjpeg \
	-DENABLE_GPGME:BOOL=OFF \
        -DENABLE_BOOST=OFF \
	-DUSE_CMS:STRING=lcms2 \
	-DENABLE_UNSTABLE_API_ABI_HEADERS=ON \
	-DFONT_CONFIGURATION:STRING=fontconfig

define Package/poppler_lede/install
	$(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include/cpp $(1)/usr/lib
	$(CP) -r $(PKG_INSTALL_DIR)/usr/include/poppler $(1)/usr/include/
	$(CP) -r $(PKG_BUILD_DIR)/cpp/poppler-version.h $(1)/usr/include/cpp
	$(CP) -r $(PKG_BUILD_DIR)/cpp/poppler-global.h $(1)/usr/include/cpp
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib
endef

$(eval $(call BuildPackage,poppler_lede))

